package com.kangyi.user.mapper;

import com.kangyi.user.annotation.AutoFill;
import com.kangyi.dto.FavoriteDTO;
import com.kangyi.entity.NursingHomeFavorite;
import com.kangyi.enumeration.OperationType;
import com.kangyi.vo.NursingHomeFavoriteVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@Mapper
public interface NursingHomeFavoriteMapper {
    List<NursingHomeFavoriteVO> listFavorite(Integer userId);

    @Insert("insert into nursing_home_favorite(user_id, nursing_home_id, create_time, update_time, create_user, update_user) " +
            "VALUES(#{userId},#{nursingHomeId},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    @AutoFill(value = OperationType.INSERT)
    void addFavorite(NursingHomeFavorite addFavoriteDTO);

    @Select("select * from nursing_home_favorite where user_id = #{userId} and nursing_home_id = #{nursingHomeId}")
    NursingHomeFavorite selectByUserIdAndNursingHomeId(FavoriteDTO favoriteDTO);

    @Select("select * from nursing_home_favorite where id = #{id}")
    NursingHomeFavorite selectById(Integer id);

    @Delete("delete from nursing_home_favorite where user_id = #{userId} and nursing_home_id = #{nursingHomeId};")
    void cancelFavorite(FavoriteDTO favoriteDTO);

    @Delete("delete from nursing_home_favorite where id = #{id}")
    void deleteById(Integer id);
}
